package edu.tapestry.iddb.client.pages.profil;

import iddb.ProfilesInfo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;

import edu.tapestry.iddb.client.entities.Profil;
import edu.tapestry.iddb.client.webService.CommandsGenerator;
import edu.tapestry.iddb.client.webService.IDDBProxy;

public class ListProfil {

	@ApplicationState
	private IDDBProxy proxy;
	
	@Property
	private Profil currentProfil;
	
	@InjectPage
	private DetailsProfil detailsPage;
	
	
	public List<Profil> getAllProfiles(){
		
		List<Profil> profiles = new ArrayList<Profil>();
		
		
		ProfilesInfo names = ((ProfilesInfo)proxy.execute(CommandsGenerator.getProfiles()));

		//*
		for(Iterator<String> ii = names.getProfiles().iterator(); ii.hasNext();){
			String name = ii.next();
			
			profiles.add(new Profil(name));
		}
		//*/
		
		return profiles;
	}
	
	public Object onActionFromDetailsLink(String profilname){
		return detailsPage.initialize(profilname);
	}


	public Profil getCurrentProfil() {
		return currentProfil;
	}


	public void setCurrentProfil(Profil profil) {
		currentProfil = profil;
	}
	
	
}
